package com.example.juyixia;

import android.os.Bundle;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.exanple.data.StrBean;
import com.exanple.data.memBean;

import android.app.Activity;
import android.app.Fragment;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseExpandableListAdapter;
import android.widget.ExpandableListView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ExpandableListView.OnChildClickListener;

public class Friend_Fragment extends Fragment  {
	private ImageView addfriend;
	private Myinfo myinfo;
	private ListView friends;
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		// TODO Auto-generated method stub
	       View view = inflater.inflate(R.layout.fragment_02, null);
	       friends = (ListView)view.findViewById(R.id.friendslist);
	        
	        //给链表添加数据
	        List<Map<String, Object>> list=getData();
	        //适配器，刚刚重写的！
	        MyAdapter myAdapter = new MyAdapter(getActivity(), list);
	        //设置适配器
	        friends.setAdapter(myAdapter);
	       
	        return view;
	}
	
	 public List<Map<String, Object>> getData() {
		    myinfo = (Myinfo) getActivity().getApplication();
	        List<Myinfo> friendsinfo = myinfo.getUserfriend();
	        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
	        for (Myinfo info : friendsinfo) {
	        	Map<String, Object> map = new HashMap<String, Object>();
	        	map.put("image",  R.drawable.ic_launcher);
	        	map.put("userid", info.getUserid());
	        	map.put("username", info.getUsername());
	        	map.put("userip", info.getUserip());
	        	 list.add(map);
			}
	       
	        return list;
	    }
	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onActivityCreated(savedInstanceState);
		addfriend =  (ImageView) getActivity().findViewById(R.id.addfriend);
		addfriend.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				addfriend = (ImageView) getActivity().findViewById(R.id.addfriend);
				Intent intent = new Intent(getActivity(), AddFriendActivity.class);
				startActivity(intent);
			}
		});
	}
   
	
}
